package com.jilefojing.convent;

import com.jilefojing.beans.data.response.base.BaseData;
import com.jilefojing.beans.data.web.response.*;
import com.jilefojing.beans.enums.ItemTypeEnumForSource;
import com.jilefojing.beans.enums.forattitude.TypeEnumForAttitude;
import com.jilefojing.beans.pojos.enhanced.*;
import com.jilefojing.beans.pojos.enhanced.base.BaseEnhanced;
import com.jilefojing.beans.vo.PlayTypeForEAudio;
import com.jilefojing.beans.vo.PlayTypeForEVideo;
import com.jilefojing.beans.vo.Source;
import com.jilefojing.util.Detect;
import com.jilefojing.util.QiniuUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;

public class CommonConvent {
	private static final Logger _LOGGER = LoggerFactory
			.getLogger(CommonConvent.class);
	private static final CommonConvent COMMON_CONVENT = new CommonConvent();

	private CommonConvent() {
	}

	public static List<BannerData> convent2BannerDatas(
			List<EnhancedBanner> enhancedBanners) {
		List<BannerData> bannerDatas = new ArrayList<BannerData>();
		for (EnhancedBanner _EnhancedBanner : enhancedBanners) {
			bannerDatas.add(convent2BannerData(_EnhancedBanner));
		}
		return bannerDatas;
	}

	public static BannerData convent2BannerData(EnhancedBanner enhancedBanner) {
		BannerData bannerData = new BannerData();

		BeanUtils.copyProperties(enhancedBanner, bannerData);

		if (enhancedBanner.getStatus() != null) {
			bannerData.setStatus(enhancedBanner.getStatus().getCode());
		}

		if (enhancedBanner.getPlatform() != null) {
			bannerData.setPlatform(enhancedBanner.getPlatform().getCode());
		}

		if (enhancedBanner.getEnhancedCreateUser() != null) {
			bannerData.setCreateuser(convent2UserData(enhancedBanner
					.getEnhancedCreateUser()));
		}

		return bannerData;
	}

	public static UserData convent2UserData(EnhancedUser enhancedUser) {
		UserData userData = new UserData();

		BeanUtils.copyProperties(enhancedUser,
				userData);

		// try {
		// BeanUtils.copyProperties(userData, enhancedUser);
		// } catch (IllegalAccessException | InvocationTargetException e) {
		// _LOGGER.error(userData.getClass() + "转换异常:" + e.getMessage(), e);
		// }

		if (enhancedUser.getStatus() != null) {
			userData.setStatus(enhancedUser.getStatus().getCode());
		}
		return userData;
	}

	public static List<RecommendData> convent2RecommendDatas(
			List<EnhancedRecommend> enhancedRecommends) {
		List<RecommendData> recommendDatas = new ArrayList<RecommendData>();
		for (EnhancedRecommend _EnhancedRecommend : enhancedRecommends) {
			recommendDatas.add(convent2RecommendData(_EnhancedRecommend));
		}
		return recommendDatas;
	}

	public static RecommendData convent2RecommendData(
			EnhancedRecommend enhancedRecommend) {
		RecommendData recommendData = new RecommendData();

		BeanUtils.copyProperties(enhancedRecommend, recommendData);

		if (enhancedRecommend.getEnhancedUser() != null) {
			recommendData.setCreateUser(convent2UserData(enhancedRecommend
					.getEnhancedUser()));
		}

		if (enhancedRecommend.getItemType() != null) {
			recommendData
					.setItemType(enhancedRecommend.getItemType().getCode());
		}
		if (enhancedRecommend.getEnhancedItem() != null
				&& enhancedRecommend.getItemType() != null) {
			recommendData.setItem((BaseData) CommonConvent.get("convent2"
					+ enhancedRecommend.getItemType().getItemClass()
							.getSimpleName() + "Data",
					enhancedRecommend.getEnhancedItem()));

			if (!Detect.notEmpty(recommendData.getCoverUrl())) {
				recommendData.setCoverUrl(enhancedRecommend.getEnhancedItem()
						.getString("getCoverUrl"));
			}
			if (!Detect.notEmpty(recommendData.getInfo())) {
				recommendData.setInfo(enhancedRecommend.getEnhancedItem()
						.getString("getInfo"));
			}
		}

		return recommendData;
	}

	public static List<VideoData> convent2EVideoDatas(
			List<EnhancedEVideo> enhancedEVideos) {
		List<VideoData> videoDatas = new ArrayList<VideoData>();
		for (EnhancedEVideo _EnhancedEVideo : enhancedEVideos) {
			videoDatas.add(convent2EVideoData(_EnhancedEVideo));
		}
		return videoDatas;
	}

	public static VideoData convent2EVideoData(EnhancedEVideo enhancedEVideo) {
		VideoData videoData = new VideoData();
		BeanUtils.copyProperties(enhancedEVideo, videoData);

		if (enhancedEVideo.getEnhancedCreateUser() != null) {
			videoData.setCreateUser(convent2UserData(enhancedEVideo
					.getEnhancedCreateUser()));
		}

		if (enhancedEVideo.getEnhancedOwner() != null) {
			videoData.setOwner(convent2UserData(enhancedEVideo
					.getEnhancedOwner()));
		}

		if (Detect.notEmpty(enhancedEVideo.getPlayTypes())) {
			videoData.setPlayTypes(convent2PlayTypeForVideoDatas(enhancedEVideo
					.getPlayTypes()));
		}
		if (enhancedEVideo.getEnhancedStatistics() != null) {
			videoData.setStatistics(convent2StatisticsData(enhancedEVideo
					.getEnhancedStatistics()));
		}

		if (enhancedEVideo.getEnhancedRFavoriteSource() != null) {
			videoData
					.setrFavoriteSource(convent2RFavoriteSourceData(enhancedEVideo
							.getEnhancedRFavoriteSource()));
		}

		if (enhancedEVideo.getEnhancedAttitude() != null) {
			if (enhancedEVideo.getEnhancedAttitude().getType() == TypeEnumForAttitude.PRAISE) {
				videoData.setPraise(true);
			} else if (enhancedEVideo.getEnhancedAttitude().getType() == TypeEnumForAttitude.UNSUPPORT) {
				videoData.setUnsupport(true);
			}
			// else TODO 继续添加类型
		}

		if (Detect.notEmpty(enhancedEVideo.getEnhancedTags())) {
			videoData
					.setTags(convent2TagDatas(enhancedEVideo.getEnhancedTags()));
		}

		long showTime;
		String showTimeStr = "";
		if (enhancedEVideo.isEntity()) {
			showTime = enhancedEVideo.getPlaytime();
		} else {
			showTime = enhancedEVideo.getCountCognatePlaytime();
		}

		if (showTime > 0) {
			int hour = (int) (showTime / 60 / 60);
			int min = (int) (showTime / 60 % 60);
			String hourStr = "";
			String minStr = "";
			if (hour > 0) {
				hourStr = hour + "时";
			}
			if (min > 0) {
				minStr = min + "分";
			}
			showTimeStr = hourStr + minStr;
		}
		videoData.setShowTime(showTimeStr);

		if (Detect.notEmpty(enhancedEVideo.getEnhancedChildren())) {
			videoData.setChildVideos(convent2EVideoDatas(enhancedEVideo
					.getEnhancedChildren()));
		}
		return videoData;
	}

	public static List<TagData> convent2TagDatas(List<EnhancedTag> enhancedTags) {
		List<TagData> tagDatas = new ArrayList<TagData>();
		for (EnhancedTag _EnhancedTag : enhancedTags) {
			tagDatas.add(convent2TagData(_EnhancedTag));
		}
		return tagDatas;
	}

	public static TagData convent2TagData(EnhancedTag enhancedTag) {
		TagData tagData = new TagData();
		BeanUtils.copyProperties(enhancedTag, tagData);
		return tagData;
	}

	public static RFavoriteSourceData convent2RFavoriteSourceData(
			EnhancedRFavoriteSource enhancedRFavoriteSource) {
		RFavoriteSourceData favoriteSourceData = new RFavoriteSourceData();
		BeanUtils.copyProperties(enhancedRFavoriteSource, favoriteSourceData);

		if (enhancedRFavoriteSource.getItemType() != null) {
			favoriteSourceData.setItemType(enhancedRFavoriteSource
					.getItemType().getCode());
		}
		if (enhancedRFavoriteSource.getEnhancedItem() != null
				&& enhancedRFavoriteSource.getItemType() != null) {
			try {
				Class<? extends BaseEnhanced> _EnhancedClass = enhancedRFavoriteSource
						.getItemType().getEnhancedItemClass();
				for (Method _Method : _EnhancedClass.getDeclaredMethods()) {
					if (_Method.getName().equals("getId")) {
						favoriteSourceData.setItemId(Long.valueOf(String
								.valueOf(_Method.invoke(enhancedRFavoriteSource
										.getEnhancedItem()))));
						break;
					}
				}
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}

		if (enhancedRFavoriteSource.getEnhancedFavorite() != null) {
			favoriteSourceData.setFavoriteId(enhancedRFavoriteSource
					.getEnhancedFavorite().getId());
		}

		return favoriteSourceData;
	}

	public static StatisticsData convent2StatisticsData(
			EnhancedStatistics enhancedStatistics) {
		StatisticsData statisticsData = new StatisticsData();

		BeanUtils.copyProperties(enhancedStatistics, statisticsData);

		String showWatchStr = "";
		if (enhancedStatistics.getCountWatch() > 9999) {
			BigDecimal showWatchBig = new BigDecimal(
					enhancedStatistics.getCountWatch() / 10000D);
			showWatchBig = showWatchBig.setScale(1, RoundingMode.HALF_UP);
			showWatchStr = showWatchBig.toString() + "万";
		} else {
			showWatchStr = enhancedStatistics.getCountWatch() + "";
		}
		showWatchStr += "次";
		statisticsData.setShowCountWatch(showWatchStr);

		String showWriteStr = "";
		if (enhancedStatistics.getCountWatch() > 9999) {
			BigDecimal showWriteBig = new BigDecimal(
					enhancedStatistics.getCountWrite() / 10000D);
			showWriteBig = showWriteBig.setScale(1, RoundingMode.HALF_UP);
			showWriteStr = showWriteBig.toString() + "万";
		} else {
			showWriteStr = enhancedStatistics.getCountWrite() + "";
		}
		showWriteStr += "次";
		statisticsData.setShowCountWrite(showWriteStr);

		String showCommentStr = "";
		if (enhancedStatistics.getCountComment() > 9999) {
			BigDecimal showCommentBig = new BigDecimal(
					enhancedStatistics.getCountComment() / 10000D);
			showCommentBig = showCommentBig.setScale(1, RoundingMode.HALF_UP);
			showCommentStr = showCommentBig.toString() + "万";
		} else {
			showCommentStr = enhancedStatistics.getCountComment() + "";
		}
		// showCommentStr += "次";
		statisticsData.setShowCountComment(showCommentStr);

		String showPraiseStr = "";
		if (enhancedStatistics.getCountPraise() > 9999) {
			BigDecimal showPraiseBig = new BigDecimal(
					enhancedStatistics.getCountPraise() / 10000D);
			showPraiseBig = showPraiseBig.setScale(1, RoundingMode.HALF_UP);
			showPraiseStr = showPraiseBig.toString() + "万";
		} else {
			showPraiseStr = enhancedStatistics.getCountPraise() + "";
		}
		// showPraiseStr += "次";
		statisticsData.setShowCountPraise(showPraiseStr);

		return statisticsData;
	}

	public static List<PlayTypeForVideoData> convent2PlayTypeForVideoDatas(
			List<PlayTypeForEVideo> playTypeForEVideos) {
		List<PlayTypeForVideoData> playTypeForVideoDatas = new ArrayList<PlayTypeForVideoData>();
		for (PlayTypeForEVideo _playTypeForEVideo : playTypeForEVideos) {
			playTypeForVideoDatas
					.add(convent2PlayTypeForVideoData(_playTypeForEVideo));
		}
		return playTypeForVideoDatas;
	}

	public static PlayTypeForVideoData convent2PlayTypeForVideoData(
			PlayTypeForEVideo playTypeForEVideo) {
		PlayTypeForVideoData playTypeForVideoData = new PlayTypeForVideoData();
		BeanUtils.copyProperties(playTypeForEVideo, playTypeForVideoData);
		return playTypeForVideoData;
	}

	public static List<CommentData> convent2CommentDatas(
			List<EnhancedComment> enhancedComments) {
		List<CommentData> commentDatas = new ArrayList<CommentData>();
		for (EnhancedComment _EnhancedComment : enhancedComments) {
			commentDatas.add(convent2CommentData(_EnhancedComment));
		}
		return commentDatas;
	}

	public static CommentData convent2CommentData(
			EnhancedComment enhancedComment) {
		CommentData commentData = new CommentData();
		BeanUtils.copyProperties(enhancedComment, commentData);

		if (enhancedComment.getEnhancedAttitude() != null) {
			if (enhancedComment.getEnhancedAttitude().getType() == TypeEnumForAttitude.PRAISE) {
				commentData.setPraise(true);
			} else if (enhancedComment.getEnhancedAttitude().getType() == TypeEnumForAttitude.UNSUPPORT) {
				commentData.setUnsupport(true);
			}
			// else TODO 继续添加类型
		}

		if (enhancedComment.getItemType() != null) {
			commentData.setItemType(enhancedComment.getItemType().getCode());
			if (enhancedComment.getEnhancedItem() != null) {
				if (enhancedComment.getItemType() == ItemTypeEnumForSource.VIDEO) {
					commentData
							.setVideo(convent2EVideoData((EnhancedEVideo) enhancedComment
									.getEnhancedItem()));
				} else if (enhancedComment.getItemType() == ItemTypeEnumForSource.AUDIO) {
					// TODO
				} else if (enhancedComment.getItemType() == ItemTypeEnumForSource.TEXT) {
					// TODO
				} else if (enhancedComment.getItemType() == ItemTypeEnumForSource.COMMENT) {
					commentData
							.setComment(convent2CommentData((EnhancedComment) enhancedComment
									.getEnhancedItem()));
				}
				// else //TODO 继续增加评论对象类型
			}

		}

		if (Detect.notEmpty(enhancedComment.getEnhancedChildCommentsForTop())) {
			commentData
					.setChildCommentsForTop(convent2CommentDatas(enhancedComment
							.getEnhancedChildCommentsForTop()));
		}

		if (enhancedComment.getEnhancedStatistics() != null) {
			commentData.setStatistics(convent2StatisticsData(enhancedComment
					.getEnhancedStatistics()));
		}

		if (enhancedComment.getEnhancedUser() != null) {
			commentData.setUser(convent2UserData(enhancedComment
					.getEnhancedUser()));
		}
		if (enhancedComment.getStatus() != null) {
			commentData.setStatus(enhancedComment.getStatus().getCode());
		}
		Calendar nowCalendar = new GregorianCalendar();
		int nowYear = nowCalendar.get(Calendar.YEAR);
		int nowMonth = nowCalendar.get(Calendar.MONTH);
		int nowDay = nowCalendar.get(Calendar.DAY_OF_MONTH);

		Calendar commentCalendar = new GregorianCalendar();
		commentCalendar.setTime(commentData.getCreateTime());
		int commentYear = commentCalendar.get(Calendar.YEAR);
		int commentMonth = commentCalendar.get(Calendar.MONTH);
		int commentDay = commentCalendar.get(Calendar.DAY_OF_MONTH);

		String showShortDate = null;
		if (nowYear == commentYear && nowMonth == commentMonth) {
			if (nowDay == commentDay) {
				showShortDate = "今天 ";
			} else if ((nowDay - 1) == commentDay) {
				showShortDate = "昨天 ";
			} else if ((nowDay - 2) == commentDay) {
				showShortDate = "前天 ";
			} else {
				showShortDate = new SimpleDateFormat("M月d日").format(commentData
						.getCreateTime());
			}
		} else if (nowYear == commentYear) {
			showShortDate = new SimpleDateFormat("M月d日").format(commentData
					.getCreateTime());
		} else {
			showShortDate = new SimpleDateFormat("yy年M月d日").format(commentData
					.getCreateTime());
		}

		String showShortTime = new SimpleDateFormat("H:mm").format(commentData
				.getCreateTime());

		String showTime = showShortDate + " " + showShortTime;

		commentData.setShowShortDate(showShortDate);
		commentData.setShowShortTime(showShortTime);
		commentData.setShowTime(showTime);
		return commentData;
	}

	public static List<DCategoryData> convent2DCategoryDatas(
			List<EnhancedDCategory> enhancedDCategories) {
		List<DCategoryData> dCategoryDatas = new ArrayList<DCategoryData>();
		for (EnhancedDCategory _EnhancedDCategory : enhancedDCategories) {
			dCategoryDatas.add(convent2DCategoryData(_EnhancedDCategory));
		}

		return dCategoryDatas;
	}

	public static DCategoryData convent2DCategoryData(
			EnhancedDCategory enhancedDCategory) {
		DCategoryData dCategoryData = new DCategoryData();
		BeanUtils.copyProperties(enhancedDCategory, dCategoryData);

		if (enhancedDCategory.getEnhancedParentDCategory() != null) {
			dCategoryData
					.setParentDCategory(convent2DCategoryData(enhancedDCategory
							.getEnhancedParentDCategory()));
		}
		if (enhancedDCategory.getEnhancedCreateUser() != null) {
			dCategoryData.setCreateUser(convent2UserData(enhancedDCategory
					.getEnhancedCreateUser()));
		}

		if (Detect.notEmpty(enhancedDCategory.getEnhancedChildDCategories())) {
			dCategoryData
					.setChildDCategories(convent2DCategoryDatas(enhancedDCategory
							.getEnhancedChildDCategories()));
		}

		return dCategoryData;
	}

	public static List<AudioData> convent2EAudioDatas(
			List<EnhancedEAudio> enhancedEAudios) {
		List<AudioData> audioDatas = new ArrayList<AudioData>();
		for (EnhancedEAudio _EnhancedEAudio : enhancedEAudios) {
			audioDatas.add(convent2EAudioData(_EnhancedEAudio));
		}
		return audioDatas;
	}

	public static AudioData convent2EAudioData(EnhancedEAudio enhancedEAudio) {
		AudioData audioData = new AudioData();
		BeanUtils.copyProperties(enhancedEAudio, audioData);

		if (enhancedEAudio.getEnhancedCreateUser() != null) {
			audioData.setCreateUser(convent2UserData(enhancedEAudio
					.getEnhancedCreateUser()));
		}

		if (enhancedEAudio.getEnhancedOwner() != null) {
			audioData.setOwner(convent2UserData(enhancedEAudio
					.getEnhancedOwner()));
		}

		if (Detect.notEmpty(enhancedEAudio.getPlayTypes())) {
			audioData.setPlayTypes(convent2PlayTypeForAudioDatas(enhancedEAudio
					.getPlayTypes()));
		}
		if (enhancedEAudio.getEnhancedStatistics() != null) {
			audioData.setStatistics(convent2StatisticsData(enhancedEAudio
					.getEnhancedStatistics()));
		}

		if (enhancedEAudio.getProgressStatus() != null) {
			audioData.setProgressStatus(enhancedEAudio.getProgressStatus()
					.getCode());
		}

		if (enhancedEAudio.getEnhancedRFavoriteSource() != null) {
			audioData
					.setrFavoriteSource(convent2RFavoriteSourceData(enhancedEAudio
							.getEnhancedRFavoriteSource()));
		}

		if (enhancedEAudio.getEnhancedAttitude() != null) {
			if (enhancedEAudio.getEnhancedAttitude().getType() == TypeEnumForAttitude.PRAISE) {
				audioData.setPraise(true);
			} else if (enhancedEAudio.getEnhancedAttitude().getType() == TypeEnumForAttitude.UNSUPPORT) {
				audioData.setUnsupport(true);
			}
			// else TODO 继续添加类型
		}

		if (Detect.notEmpty(enhancedEAudio.getEnhancedTags())) {
			audioData
					.setTags(convent2TagDatas(enhancedEAudio.getEnhancedTags()));
		}

		long showTime;
		String showTimeStr = "";
		if (enhancedEAudio.isEntity()) {
			showTime = enhancedEAudio.getPlaytime();
		} else {
			showTime = enhancedEAudio.getCountCognatePlaytime();
		}

		if (showTime > 0) {
			int hour = (int) (showTime / 60 / 60);
			int min = (int) (showTime / 60 % 60);
			String hourStr = "";
			String minStr = "";
			if (hour > 0) {
				hourStr = hour + "时";
			}
			if (min > 0) {
				minStr = min + "分";
			}
			showTimeStr = hourStr + minStr;
		}
		audioData.setShowTime(showTimeStr);

		if (Detect.notEmpty(enhancedEAudio.getEnhancedChildren())) {
			audioData.setChildAudios(convent2EAudioDatas(enhancedEAudio
					.getEnhancedChildren()));
		}
		return audioData;
	}

	public static List<PlayTypeForAudioData> convent2PlayTypeForAudioDatas(
			List<PlayTypeForEAudio> playTypeForEAudios) {
		List<PlayTypeForAudioData> playTypeForAudioDatas = new ArrayList<PlayTypeForAudioData>();
		for (PlayTypeForEAudio _playTypeForEAudio : playTypeForEAudios) {
			playTypeForAudioDatas
					.add(convent2PlayTypeForAudioData(_playTypeForEAudio));
		}
		return playTypeForAudioDatas;
	}

	public static PlayTypeForAudioData convent2PlayTypeForAudioData(
			PlayTypeForEAudio playTypeForEAudio) {
		PlayTypeForAudioData playTypeForAudioData = new PlayTypeForAudioData();
		BeanUtils.copyProperties(playTypeForEAudio, playTypeForAudioData);
		return playTypeForAudioData;
	}

	public static Object get(String method, Object value) {
		try {
			for (Method _Method : CommonConvent.class.getDeclaredMethods()) {
				if (_Method.getName().equals(method)) {
					return _Method.invoke(COMMON_CONVENT, value);
				}
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static List<ArticleData> convent2EArticleDatas(
			List<EnhancedEArticle> enhancedEArticles) {
		List<ArticleData> articleDatas = new ArrayList<ArticleData>();
		for (EnhancedEArticle _EnhancedEArticle : enhancedEArticles) {
			articleDatas.add(convent2EArticleData(_EnhancedEArticle));
		}
		return articleDatas;
	}

	public static ArticleData convent2EArticleData(
			EnhancedEArticle enhancedEArticle) {
		ArticleData articleData = new ArticleData();
		BeanUtils.copyProperties(enhancedEArticle, articleData);

		if (enhancedEArticle.getEnhancedCreateUser() != null) {
			articleData.setCreateUser(convent2UserData(enhancedEArticle
					.getEnhancedCreateUser()));
		}

		// if (enhancedEArticle.getEnhancedOwner() != null) {
		// articleData.setOwner(convent2UserData(enhancedEArticle
		// .getEnhancedOwner()));
		// }

		if (enhancedEArticle.getEnhancedStatistics() != null) {
			articleData.setStatistics(convent2StatisticsData(enhancedEArticle
					.getEnhancedStatistics()));
		}

		if (enhancedEArticle.getProgressStatus() != null) {
			articleData.setProgressStatus(enhancedEArticle.getProgressStatus()
					.getCode());
		}

		if (enhancedEArticle.getEnhancedRFavoriteSource() != null) {
			articleData
					.setrFavoriteSource(convent2RFavoriteSourceData(enhancedEArticle
							.getEnhancedRFavoriteSource()));
		}

		if (enhancedEArticle.getEnhancedAttitude() != null) {
			if (enhancedEArticle.getEnhancedAttitude().getType() == TypeEnumForAttitude.PRAISE) {
				articleData.setPraise(true);
			} else if (enhancedEArticle.getEnhancedAttitude().getType() == TypeEnumForAttitude.UNSUPPORT) {
				articleData.setUnsupport(true);
			}
			// else TODO 继续添加类型
		}

		if (Detect.notEmpty(enhancedEArticle.getEnhancedTags())) {
			articleData.setTags(convent2TagDatas(enhancedEArticle
					.getEnhancedTags()));
		}

		if (enhancedEArticle.getCopyPublishTime() != null) {
			articleData.setShowTime(new SimpleDateFormat("yyyy-MM-dd")
					.format(enhancedEArticle.getCopyPublishTime()));
		}

		if (Detect.notEmpty(enhancedEArticle.getEnhancedChildren())) {
			articleData.setChildArticles(convent2EArticleDatas(enhancedEArticle
					.getEnhancedChildren()));
		}

		if (Detect.notEmpty(enhancedEArticle.getContent())) {
			Document doc = Jsoup.parse(enhancedEArticle.getContent());
			String contentText = doc.text();
			if (contentText.length() <= 100) {
				articleData.setSummary(contentText);
			} else {
				articleData.setSummary(contentText.substring(0, 101) + "...");
			}

			String coverUrl = null;
			Elements imgElements = doc.select("img[src]");
			if (imgElements.size() > 0) {
				coverUrl = imgElements
						.get(0)
						.attr("src")
						.trim()
						.replaceAll("\\$_PREFIX_\\$",
								QiniuUtil.getImagesDomain());
				articleData.setCoverUrl(coverUrl);
			}

		}
		if (Detect.notEmpty(enhancedEArticle.getEnhancedDCategories())) {
			articleData.setCategory(convent2DCategoryData(enhancedEArticle
					.getEnhancedDCategories().get(0)));
		}
		return articleData;
	}

	public static List<SourceData> convent2SourceDatas(List<Source> sources) {
		List<SourceData> sourceDatas = new ArrayList<SourceData>();
		for (Source _Source : sources) {
			sourceDatas.add(convent2SourceData(_Source));
		}
		return sourceDatas;
	}

	public static SourceData convent2SourceData(Source source) {
		SourceData sourceData = new SourceData();
		BeanUtils.copyProperties(source, sourceData);
		Date showTimeDate = source.getCopyTime() == null ? source
				.getUpdateTime() : source.getCopyTime();
		if (showTimeDate != null) {
			sourceData.setShowTime(new SimpleDateFormat("yyyy-MM-dd")
					.format(showTimeDate));
		}

		if (Detect.notEmpty(source.getInfo())) {
			Document doc = Jsoup.parse(source.getInfo());
			String summary = doc.text();
			if (summary.length() > 199) {
				summary = summary.substring(0, 200) + "...";
			}
			sourceData.setSummary(summary);
		}

		return sourceData;
	}

	public static List<BookChapterData> convent2EBookChapterDatas(
			List<EnhancedEBookChapter> enhancedEBookChapters) {
		List<BookChapterData> bookChapterDatas = new ArrayList<BookChapterData>();

		for (EnhancedEBookChapter _EnhancedEBookChapter : enhancedEBookChapters) {
			bookChapterDatas
					.add(convent2EBookChapterData(_EnhancedEBookChapter));
		}
		return bookChapterDatas;
	}

	public static BookChapterData convent2EBookChapterData(
			EnhancedEBookChapter enhancedEBookChapter) {
		BookChapterData bookChapterData = new BookChapterData();
		BeanUtils.copyProperties(enhancedEBookChapter, bookChapterData);

		if (enhancedEBookChapter.getEnhancedCreateUser() != null) {
			bookChapterData.setCreateUser(convent2UserData(enhancedEBookChapter
					.getEnhancedCreateUser()));
		}

		if (enhancedEBookChapter.getEnhancedStatistics() != null) {
			bookChapterData
					.setStatistics(convent2StatisticsData(enhancedEBookChapter
							.getEnhancedStatistics()));
		}
		if (Detect.notEmpty(enhancedEBookChapter.getContent())) {
			Document doc = Jsoup.parse(enhancedEBookChapter.getContent());
			String contentText = doc.select("p").text();
			bookChapterData.setContentText(contentText);
			String contentTextTrim = contentText.replaceAll("\\pP|\\pZ", "");
			bookChapterData.setContentTextLength(contentTextTrim.length());
		}

		return bookChapterData;
	}
}
